import { applyMiddleware, createStore } from 'redux';
import thunkMiddleware from 'redux-thunk';
import {createLogger} from 'redux-logger';
import rootReducer from '../reducers/index';
import {AsyncStorage} from 'react-native';
import {persistStore, persistCombineReducers} from 'redux-persist';
import storage from 'redux-persist/es/storage'
var isDebuggingInChrome = __DEV__ && !!window.navigator.userAgent;

var logger = createLogger({
    predicate: (getState, action) => isDebuggingInChrome,
    collapsed: true,
    duration: true,
});


export default function configureStore() {

    const middleware = applyMiddleware(thunkMiddleware, logger);



    // const store = persistCombineReducers()(createStore)(rootReducer);
    // persistStore(store, {storage: AsyncStorage});


    // const store = middleware(createStore)(rootReducer);

    // if (module.hot) {
    //     // Enable Webpack hot module replacement for reducers
    //     module.hot.accept('../reducers/index', () => {
    //         const nextRootReducer = require('../reducers/index').default;
    //         store.replaceReducer(nextRootReducer);
    //     });
    // }


    let store = middleware(createStore)(rootReducer)
    let persistor = persistStore(store)

    return { persistor, store }
}